package com.like.hospitalworld;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.like.adapter.MsgPagerAdapter;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

@ContentView(R.layout.activity_message)
public class MessageActivity extends BaseActivity {

    @ViewInject(R.id.viewpager_msg)
    private ViewPager mViewPager;

    @ViewInject(R.id.radio_my_msg)
    private RadioButton mMsgRadio;
    @ViewInject(R.id.radio_system_msg)
    private RadioButton mSysRadio;

    private MsgPagerAdapter msgPagerAdapter;
    private List<RadioButton> mTabList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mTabList.add(mMsgRadio);
        mTabList.add(mSysRadio);

        msgPagerAdapter = new MsgPagerAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(msgPagerAdapter);

        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(int position) {
                clearCheck();
                mTabList.get(position).setChecked(true);
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });

        mMsgRadio.setChecked(true);

    }

    @Event(value = R.id.radio_my_msg, type = CompoundButton.OnCheckedChangeListener.class)
    private void videoCheck(CompoundButton buttonView, boolean isChecked) {
        if (isChecked) {
            mViewPager.setCurrentItem(0);
        }
    }

    @Event(value = R.id.radio_system_msg, type = CompoundButton.OnCheckedChangeListener.class)
    private void coursewareCheck(CompoundButton buttonView, boolean isChecked) {
        if (isChecked) {
            mViewPager.setCurrentItem(1);
        }
    }

    private void clearCheck() {
        for (RadioButton radio : mTabList) {
            radio.setChecked(false);
        }
    }
}
